import java.time.LocalDate;

public class CourtOccupation {

    private static final int HOURS_OF_DAY = 24;
    private static final int DAYS_OF_WEEK = 7;

    private boolean[][] hoursTaken;
    private int dayStart;
    private int dayEnd;

    public CourtOccupation(int start, int end) {
        this.dayStart = start;
        this.dayEnd = end;
        this.hoursTaken = new boolean[DAYS_OF_WEEK][HOURS_OF_DAY];
        for (int i = 0; i < DAYS_OF_WEEK; i++)
            for (int j = 0; j < HOURS_OF_DAY; j++)
                this.hoursTaken[i][j] = false;
    }

    public boolean checkOccupied (int day, int begin, int end) throws Exception {
        if (begin < this.dayStart || end > this.dayEnd)
            throw new Exception("EXCEPTION: Out of range!");

        for (int i = begin; i < end; i++)
            if (this.hoursTaken[day - 1][i])
                return true;

        return false;
    }

    public void setOccupied(int day, int begin, int end) {
        for (int i = begin; i < end; i++)
            this.hoursTaken[day - 1][i] = true;
    }

    public void clearOccupied(int day, int begin, int end) {
        for(int i = begin; i < end; i++)
            this.hoursTaken[day - 1][i] = false;
    }
}